#include "mainscene.h"
#include "ui_mainscene.h"
#include<QPainter>
#include<mypushbutton.h>
#include<QDebug>
#include<QTimer>
#include<QSound>
#include<QMediaPlayer>

MainScene::MainScene(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainScene)
{
    ui->setupUi(this);

    //配置主场景

    //设置固定大小
//    setFixedSize(320,588);
    setFixedSize(390,640);
    //设置图标
    setWindowIcon(QIcon(":/res/Coin0001"));
    //设置标题
    setWindowTitle("啊哈哈哈，翻金币来喽！");
    //设置退出
    connect(ui->actionquit,&QAction::triggered,[=](){
        this->close();
    });


    //开始按钮音效创建
    QSound *startSound =new QSound(":/res/TapButtonSound.wav",this);

    //开始背景音效创建
    QSound *startBkSound =new QSound(":/res/JT01main.wav",this);
    startBkSound->play();

    //创建开始按钮
    MyPushButton *startbtn=new MyPushButton(":/res/MenuSceneStartButton.png");
    startbtn->setParent(this);
    startbtn->move(this->width()/2-startbtn->width()/2,this->height()*0.7);



    connect(startbtn,&MyPushButton::clicked,[=](){
//       qDebug()<<"点击了开始按钮";

    startBkSound->stop();

    //音效播放
    startSound->play();
    //做弹起特效
    startbtn->zoom1();
    startbtn->zoom2();

    //实例化选择关卡场景
    chooseScene =new ChooseLevelScene;

    //监听选择关卡back按钮信号
    connect(chooseScene,&ChooseLevelScene::chooseSceneBack,this,[=](){
        this->setGeometry(chooseScene->geometry());
        chooseScene->hide();
        this->show();
        startBkSound->play();
    });




    //延时进入选择关卡场景
    QTimer::singleShot(400,this,[=](){
        //设置选关窗口位置
        chooseScene->setGeometry(this->geometry());

        startBkSound->stop();
        //主场景自身隐藏
        this->hide();
        //显示选择关卡
        chooseScene->show();

    });


   });
}

void MainScene::paintEvent(QPaintEvent *){
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/res/PlayLevelSceneBg.png");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);//拉伸适配

    //背景图标
    pix.load(":/res/Title.png");
    pix=pix.scaled(pix.width()*0.5,pix.height()*0.5);
    painter.drawPixmap(10,30,pix);



}

MainScene::~MainScene()
{
    delete ui;
}

